<?php
namespace app\admin\model;

use \think\Db;

/**
 * 左侧菜单栏模型类
 */
class Menu extends Base
{
    //菜单
    static protected function _get_child($data, $pid=0){
        //echo "<pre>";print_r($data);echo "<pre>";;exit;
        $array = array();
        foreach ($data as $k => $v){
            if ($v['p_id'] == $pid){
                //$v['child'] = self::_get_child($data, $v['menu_id']); //递归
                if (!array_key_exists('child', $v)) {//判断$v里面有没有child这个key
                    $v['child'] = self::_get_child($data, $v['id']); //递归
                }
                $array[] = $v;
            }
        }
        return $array;
    }

    //左边栏列表
    public static function menuData()
    {
        /*$agent = "4";
        $video = "6";
        $temp_arr = [];*/
        $menu_data = Db::name('menu')->field('id,p_id,name,url,flag,class')->select();
        //echo "<pre>";print_r($menu_data);echo "<pre>";;exit;
        //unset($menu_data["2"]);
        //unset($menu_data["4"]);
        unset($menu_data["29"]);//图片库
        unset($menu_data["16"]);//4G
        unset($menu_data["24"]);//工单
        unset($menu_data["25"]);//系统设置

        //echo "<pre>";print_r($menu_data);echo "<pre>";;exit;
        $menu =self::_get_child($menu_data);
        //echo "<pre>";print_r($menu);echo "<pre>";;exit;
        return $menu;
    }
}